/*     */ package com.zimbra.qa.unittest.prov.ldap;
/*     */ 
/*     */ import com.zimbra.common.account.ZAttrProvisioning.GalMode;
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.mailbox.ContactConstants;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.GalContact;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Provisioning.GalMode;
/*     */ import com.zimbra.cs.account.Provisioning.SearchGalResult;
/*     */ import com.zimbra.cs.account.gal.GalOp;
/*     */ import com.zimbra.cs.gal.GalSearchConfig.GalType;
/*     */ import com.zimbra.cs.gal.GalSearchParams;
/*     */ import com.zimbra.qa.unittest.prov.Names;
/*     */ import com.zimbra.qa.unittest.prov.ProvTest.SkipTestReason;
/*     */ import com.zimbra.soap.type.GalSearchType;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Ignore;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestLdapProvGal
/*     */   extends LdapTest
/*     */ {
/*     */   private static LdapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  46 */     provUtil = new LdapProvTestUtil();
/*  47 */     prov = provUtil.getProv();
/*  48 */     domain = provUtil.createDomain(baseDomainName());
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  53 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */   private Account createAccount(String localPart) throws Exception {
/*  57 */     return createAccount(localPart, null);
/*     */   }
/*     */   
/*     */   private Account createAccount(String localPart, Map<String, Object> attrs) throws Exception {
/*  61 */     return provUtil.createAccount(localPart, domain, attrs);
/*     */   }
/*     */   
/*     */   private void deleteAccount(Account acct) throws Exception {
/*  65 */     provUtil.deleteAccount(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void checkGalConfig() throws Exception {
/*  70 */     String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
/*  71 */     Account acct = createAccount(ACCT_NAME_LOCALPART);
/*     */     
/*  73 */     Map<String, Object> attrs = new HashMap();
/*  74 */     attrs.put("zimbraGalMode", Provisioning.GalMode.ldap.name());
/*  75 */     attrs.put("zimbraGalLdapURL", "ldap://" + LC.zimbra_server_hostname.value() + ":389");
/*  76 */     attrs.put("zimbraGalLdapFilter", "(mail=*%s*)");
/*     */     
/*  78 */     attrs.put("zimbraGalLdapBindDn", "cn=config");
/*  79 */     attrs.put("zimbraGalLdapBindPassword", "zimbra");
/*     */     
/*  81 */     String query = "checkGalConfig";
/*  82 */     int limit = 0;
/*  83 */     GalOp galOp = GalOp.search;
/*  84 */     prov.checkGalConfig(attrs, query, limit, galOp);
/*     */     
/*  86 */     deleteAccount(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void searchGal() throws Exception {
/*  91 */     SKIP_FOR_INMEM_LDAP_SERVER(ProvTest.SkipTestReason.DN_SUBTREE_MATCH_FILTER);
/*     */     
/*  93 */     int NUM_ACCTS = 10;
/*  94 */     int SIZE_LIMIT = 5;
/*     */     
/*  96 */     Account user = null;
/*  97 */     for (int i = 0; i < NUM_ACCTS; i++) {
/*  98 */       String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart(String.valueOf(i)));
/*  99 */       Account acct = createAccount(ACCT_NAME_LOCALPART);
/*     */       
/*     */ 
/* 102 */       if (user == null) {
/* 103 */         user = acct;
/*     */       }
/*     */     }
/*     */     
/* 107 */     GalSearchType type = GalSearchType.account;
/* 108 */     String query = "searchGal";
/*     */     
/* 110 */     GalSearchParams params = new GalSearchParams(user);
/* 111 */     Provisioning.SearchGalResult result = Provisioning.SearchGalResult.newSearchGalResult(null);
/*     */     
/* 113 */     params.setOp(GalOp.search);
/* 114 */     params.setType(type);
/* 115 */     params.createSearchConfig(GalSearchConfig.GalType.zimbra);
/* 116 */     params.setQuery(query);
/* 117 */     params.setLimit(SIZE_LIMIT);
/* 118 */     params.setGalResult(result);
/* 119 */     prov.searchGal(params);
/*     */     
/* 121 */     Assert.assertEquals(SIZE_LIMIT, result.getMatches().size());
/* 122 */     Assert.assertTrue(result.getHadMore());
/*     */     
/* 124 */     result = prov.searchGal(domain, query, type, 0, null);
/* 125 */     Assert.assertEquals(NUM_ACCTS, result.getMatches().size());
/* 126 */     Assert.assertFalse(result.getHadMore());
/*     */   }
/*     */   
/*     */   @Test
/*     */   @Ignore
/*     */   public void searchGalADGroupMember() throws Exception {
/* 132 */     String DOMAIN_NAME = genDomainSegmentName() + "." + baseDomainName();
/*     */     
/* 134 */     Map<String, Object> domainAttrs = new HashMap();
/* 135 */     domainAttrs.put("zimbraGalMode", ZAttrProvisioning.GalMode.ldap.name());
/*     */     
/*     */ 
/*     */ 
/* 139 */     domainAttrs.put("zimbraGalLdapURL", "ldap://XXX.vmware.com:3268");
/* 140 */     domainAttrs.put("zimbraGalLdapBindDn", "XXX@vmware.com");
/* 141 */     domainAttrs.put("zimbraGalLdapBindPassword", "XXX");
/*     */     
/* 143 */     domainAttrs.put("zimbraGalLdapFilter", "ad");
/* 144 */     domainAttrs.put("zimbraGalLdapGroupHandlerClass", "com.zimbra.cs.gal.ADGalGroupHandler");
/* 145 */     Domain galDomain = provUtil.createDomain(DOMAIN_NAME, domainAttrs);
/*     */     
/* 147 */     String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart("searchGalADGroupMember");
/* 148 */     Account user = provUtil.createAccount(ACCT_NAME_LOCALPART, galDomain, null);
/*     */     
/* 150 */     GalSearchType type = GalSearchType.group;
/* 151 */     String query = "server-pm@vmware.com";
/*     */     
/* 153 */     GalSearchParams params = new GalSearchParams(user);
/* 154 */     Provisioning.SearchGalResult result = Provisioning.SearchGalResult.newSearchGalResult(null);
/*     */     
/* 156 */     params.setOp(GalOp.search);
/* 157 */     params.setType(type);
/* 158 */     params.setFetchGroupMembers(true);
/* 159 */     params.createSearchConfig(GalSearchConfig.GalType.ldap);
/* 160 */     params.setQuery(query);
/* 161 */     params.setGalResult(result);
/*     */     
/* 163 */     prov.searchGal(params);
/* 164 */     Assert.assertEquals(1L, result.getMatches().size());
/* 165 */     GalContact galContact = (GalContact)result.getMatches().get(0);
/* 166 */     Assert.assertTrue(galContact.isGroup());
/* 167 */     Map<String, Object> galEntryAttrs = galContact.getAttrs();
/* 168 */     Object members = galEntryAttrs.get(ContactConstants.A_member);
/* 169 */     Assert.assertTrue(members instanceof String[]);
/* 170 */     Assert.assertEquals(6L, ((String[])members).length);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/ldap/TestLdapProvGal.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */